package 栈;

import java.util.HashMap;
import java.util.Stack;

public class _856_括号的分数 {
	private HashMap<Character, Character> map = new HashMap<Character, Character>();

	public _856_括号的分数() {
		map.put('(', ')');
	}

	public int scoreOfParentheses(String S) {
		Stack<Character> stack1 = new Stack<Character>();
//		Stack<Character> stack2 = new Stack<Character>();
		int sum = 0;
		for (int i = 0; i < S.length(); i++) {
			char c = S.charAt(i);
			
			if (stack1.isEmpty()) {
				stack1.push(c);
				
			} else {
				
				if (stack1.peek() != map.get(c)) {
					stack1.push(c);
					
				} else {
					stack1.pop();
					
				}
			}
		
		}
		return sum;

	}
}
